package com.gxa.user.recycling.service.impl;

import com.gxa.core.recycling.pojo.Recycleorder;
import com.gxa.core.recycling.service.impl.BaseServiceImpl;
import com.gxa.core.recycling.util.RandomUtil;
import com.gxa.user.recycling.mapper.RecycleorderMapper;
import com.gxa.user.recycling.service.RecycleorderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author xhy
 * @Date 2021/12/2 10:22
 */
@Service("recycleorderService")
@Transactional(rollbackFor = {Throwable.class})
public class RecycleorderServiceImpl extends BaseServiceImpl<Recycleorder> implements RecycleorderService {
    @Resource
    RecycleorderMapper recycleorderMapper = null;
    @Override
    public List<Map> findRecycleorderById(Long id, String state) {
        return recycleorderMapper.findRecycleorderById(id, state);
    }

    @Override
    public List<Map> findRecycleorderDetails(Long id) {
        return recycleorderMapper.findRecycleorderDetails(id);
    }

    @Override
    public List<Map> findGoodsorder(Long id, String state) {
        return recycleorderMapper.findGoodsorder(id, state);
    }

    @Override
    public String addRecyclOrder(Long id,String title, Date ytime, Long did, Long zid) {
        Recycleorder recycleorder = new Recycleorder();
        recycleorder.setTitle(title);
        recycleorder.setZid(zid);
        recycleorder.setDid(did);
        recycleorder.setYtime(ytime);
        recycleorder.setState("待接单");
        Integer randomNumber = RandomUtil.getRandomNumber();
        recycleorder.setCode(randomNumber.toString());
        recycleorder.setUid(id);
        recycleorder.setOrdertime(new Date(System.currentTimeMillis()));
        recycleorderMapper.insert(recycleorder);
        return randomNumber.toString();
    }
}
